import java.util.Scanner;
import java.util.ArrayList;

public class javazfx {
    public static void main(String args[]){
        Scanner reader = new Scanner(System.in);
        ArrayList<Integer> numbers = new ArrayList<>();
        int max = 0, min = 10000;
        int max_p = 0, min_p = 0;
        int position = 0;
        int tmp, i;
        while(reader.hasNext())
        {
            tmp = reader.nextInt();
            if(tmp > max){
                max = tmp;
                max_p = position;
            }
            else if(tmp < min){
                min = tmp;
                min_p = position;
            }
            numbers.add(tmp);
            position+= 1;
        }
        for(i=0; i<numbers.size(); i++){
            System.out.println(numbers.get(i));
        }
        int first = numbers.get(0);
        int last = numbers.get(position-1);
        numbers.set(0, max);
        numbers.set(max_p, first);
        numbers.set(min_p, last);
        numbers.set(position-1, min);
        for(i=0; i<numbers.size(); i++){
            System.out.println(numbers.get(i));
        }
    }
}
